package component.controls.group
{
	import component.controls.Box;
	import component.controls.CheckBox;
	import component.controls.ui.Component;
	import component.global.ComponentSetting;
	import component.global.consts.Directions;
	import component.global.utils.DisplayUtils;
	import component.global.utils.ObjectUtil;
	
	public class CheckBoxGroup extends Component
	{
		public function CheckBoxGroup(direction:String = Directions.HORIZONTAL, spacing:int = ComponentSetting.BOX_DEFAULT_SPACING)
		{
			_direction = direction;
			_spacing = spacing;
			super();
		}
		
		protected var _direction:String;
		protected var _spacing:int;
		protected var _items:Vector.<CheckBox>;
		protected var _box:Box;
		protected var _selectedIndex:int = -1;
		
		override protected function init():void{
			_items = new Vector.<CheckBox>();
			_box = new Box(_direction,_spacing);
			
			DisplayUtils.addDisplayObject(this,_box);
		}
		
		public function get selectedItems():Array{
			var arr:Array = [];
			for (var i:int = 0; i < _items.length; i++) 
			{
				if(_items[i].selected)arr.push(arr);
			}
			return arr;
		}
		
		public function getItemByIndex(idx:int):CheckBox{
			return _items[idx];
		}
		
		public function addItem(label:String):void{
			var btn:CheckBox = new CheckBox(label,false);
			_items.push(btn);
			_box.addContent(btn);
		}
		
		override public function dispose():void{
			super.dispose();
			ObjectUtil.dispose(_box);_box=null;
			ObjectUtil.disposeElements(_items);_items = null;
		}
	}
}